package com.dfy.config;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import java.io.IOException;

public class PercentageDeserializer extends JsonDeserializer<Double> {
    @Override
    public Double deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        String value = p.getText();
        if (value == null || value.isEmpty()) {
            return null;
        }
        // 移除百分号并转换为小数
        value = value.replace("%", "");
        try {
            return Double.parseDouble(value) / 100.0;
        } catch (NumberFormatException e) {
            return null;
        }
    }
} 